
package air.pagehandler;

import air.eb.Airport;
import air.sb.AirRemote;
import air.sb.LuftRemote;
import air.sb.SASRemote;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
 *
 * @author Keith Augustsson
 */
public class startBean {

    AirRemote bean = lookupAirBean();
    LuftRemote lbean = lookupLuftBean();
    SASRemote sbean = lookupSASBean();

    public Collection<Airport> getList(){
        bean.findAllAirports();
        lbean.findAllAirports();
        sbean.findAllAirports();

        ArrayList al = new ArrayList();
        al.addAll(bean.getAllAirports());
        al.addAll(lbean.getAllAirports());
        al.addAll(sbean.getAllAirports());
        return new HashSet(al);
    }

    private AirRemote lookupAirBean() {
        try {
            Context c = new InitialContext();
            return (AirRemote) c.lookup("java:comp/env/AirBean");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    private LuftRemote lookupLuftBean() {
        try {
            Context c = new InitialContext();
            return (LuftRemote) c.lookup("java:comp/env/LuftBean");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    private SASRemote lookupSASBean() {
        try {
            Context c = new InitialContext();
            return (SASRemote) c.lookup("java:comp/env/SASBean");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
